import requests
import json
import base64
from pathlib import Path

def test_api_direct():
    """直接使用HTTP请求测试API"""
    
    # API配置
    base_url = "https://envision-research.hkust-gz.edu.cn/vlm_cloth_api"
    api_url = f"{base_url}/api/predict"
    
    # 准备图片数据
    image_path = "imgs/annotated_current_view.jpg"

    with open(image_path, "rb") as f:
        image_data = base64.b64encode(f.read()).decode()
    
    # 构建请求数据
    payload = {
        "data": [
            f"data:image/png;base64,{image_data}",
            "Grab the shoulders and throw the clothes"
        ],
        "fn_index": 0
    }
    
    # 发送请求
    response = requests.post(api_url, json=payload)
    print(f"Response: {response.json()['data'][0]}")
    
    return response

if __name__ == "__main__":
    test_api_direct()